<template>
  <div class="timedownload">
    <!-- 面包屑 -->
    <Headline :headline1="$t('m.AccessAdmin')+'  /  '" :headline2="$t('m.PeriodDownloadStatus')"></Headline>
    <a-card style="width: 100%">
      <div class="search">
        <div class="search-a ov_flex">
          <a-select
            v-model="TimeList.downStatus"
            class="select-a"
            @change="downleSelectChange"
          >
            <a-select-option v-for="item in dictionariesA" :value="item.code" :key="item.code">{{item.name}}</a-select-option>
        
          </a-select>
          <a-input-search
            class="input-a"
            :placeholder="$t('m.PleaseEnterYourSearchTerms')"
            style="height: 32px"
            size="large"
            v-model="TimeList.key"
            @search="downSearch"
          />
        </div>
        <div class="btns">
          <a-button
            @click="downlode"
            type="primary"
            style="width: 100%; height: 32px"
          >
            {{$t('m.ReDownload')}}
          </a-button>
        </div>
      </div>
      <a-table
        class="tables"
        :columns="columns"
        :pagination="false"
        :rowKey="(record) => record.id"
        :data-source="items"
        bordered
        :row-selection="{
          onChange: timeSelectChange,
          type: 'checkbox',
          selectedRowKeys: timesclete,
        }"
      >
       <div slot="index" slot-scope="text, tag, i">
          {{ i + 1 }}
        </div></a-table>
      <a-pagination
        class="pages"
        show-size-changer
        :defaultPageSize="5"
        :default-current="1"
        :total="total"
        @change="timePages"
        :pageSizeOptions="['5', '10', '30', '40']"
        @showSizeChange="timeShowupilChange"
      />
    </a-card>
      <Delete ref="timedelete" :dalete="dalete" @confirm="timedelete"></Delete>
  </div>
</template>

<script>
import Headline from "@/components/Headline";
import Modal from "@/components/common/Modal";
import Delete from "@/components/Delete";
import { getdiction } from "@/api/dictionaries";
import { getDoorTimeList,getReDownload } from "@/api/entrance/entranceguard";
export default {
  name: "TimeDownload",
  components: { Headline, Modal, Delete},
  data() {
    return {
      columns: [
        {
          title: this.$t('m.SerialNumber'),
          scopedSlots: { customRender: "index" },
        },
        { title: this.$t('m.DownloadStatus'), dataIndex: "statusname" },
        { title: this.$t('m.deviceNumber'), dataIndex: "machineid" },
        { title: this.$t('m.EquipmentName'), dataIndex: "devname" },
        { title: this.$t('m.DoorReadingHead'), dataIndex: "readheadname" },
        { title: this.$t('m.Relay'), dataIndex: "relays" },
        { title: this.$t('m.TimeSerialNumber'), dataIndex: "timeindex" },
        { title: this.$t('m.Start'), dataIndex: "starttime" },
        { title: this.$t('m.End'), dataIndex: "endtime" },
        { title: this.$t('m.openDay'),
         dataIndex: "weekvalue",
           customRender: function (text, record, index) {
           let num = ['周日','一','二','三','四','五','六','假日']
           let arr = text.split(",")
           var slet=""
           arr.forEach((el,index) => {
               if(el==1){
                   if(index ==num.length-1){
                    slet+=num[index]
                   }else{
                        slet+=num[index]+'、'
                   }
                  
               }
           })
          return slet
          },
         },
        { title: this.$t('m.periodofvalidity'), dataIndex: "enddate" },
        { title: this.$t('m.processingTime'), dataIndex: "downtime" },
        { title: this.$t('m.ProcessingTimes'), dataIndex: "downnum" },
        { title: this.$t('m.theResults'), dataIndex: "downmsg" },
      ],
      items: [],
      TimeList: {
        key: "",
        downStatus: "-1",
        start: 0,
        limit: 10,
        page: 1,
      },
      total: 0,
      timesclete: [],
      doorIds:"",
       dalete: {
        titles: this.$t('m.ChangeThePrompt'),
        type: "exclamation-point",
        text: this.$t('m.AreYouSureToChangeData'),
      },
        fromdic: {
        groupcode: "SYS0000025",
        insertall: "-1|全部",
        where: "code<> -1 and code <> -100",
      },
      dictionariesA: [],
    };
  },
  created() {
    this._getDoorTimeList();
        this._getdiction();
  },
  methods: {
      _getdiction() {
      getdiction({ params: this.fromdic }).then((res) => {
        console.log(res);
        this.dictionariesA = res.data.data;
      });
    
    },
    //获取列表数据
    _getDoorTimeList() {
      getDoorTimeList({ params: this.TimeList }).then((res) => {
        console.log(res);
        if (res.data.success) {
          this.$message.success("获取数据成功");
          this.items = res.data.data;
          this.total = res.data.total;
        }
      });
    },
    //Select选中
    downleSelectChange() {
      this._getDoorTimeList();
    },
    //搜索
    downSearch() {
      this._getDoorTimeList();
    },
    //重新下载
    downlode() {
        if(this.timesclete.length!==0){
          this.$refs.timedelete.visible= true
        }else{
            this.$message.error("请选择数据")
        }
    },
    //重新下载确定
    timedelete(){
      getReDownload({doorIds:this.doorIds}).then(res=>{
          console.log(res)
          const msg = res.data.msg
          if(res.data.success){
              this.$message.success(msg)
              this.timesclete= []
              this.doorIds = ""
          }else{
              this.$message.error(msg)
          }
      }).catch(err=>{
          console.log(err)
      })
       this.$refs.timedelete.visible= false
    },
    //列表选中事件
    timeSelectChange(select, text) {
      console.log(select, text);
      let str = select.join(",");
      this.timesclete = select;
      this.doorIds = str
    },
    //分页事件
    timePages(page, limit) {
      console.log(page, limit);
      this.TimeList.page = page;
      this.TimeList.limit = limit;
      this.TimeList.start = (page - 1) * limit;
      this._getDoorTimeList();
    },
    timeShowupilChange(page, pageSize) {
      this.TimeList.page = page;
      this.TimeList.limit = pageSize;
      this.TimeList.start = (page - 1) * pageSize;
      this._getDoorTimeList();
    },
  },
};
</script>

<style scoped lang="scss" >
.search {
  display: flex;
  height: 35px;
}
.search-a {
  width: 300px;
  height: 32px;
}
.ov_flex {
  display: flex;
  align-items: center;
}
/deep/ .ant-select-selection {
  width: 100px;
  height: 32px;
}
/deep/ .ant-select-selection__rendered {
  line-height: 32px;
}
.btns {
  margin-left: 15px;
}
/deep/ .ant-select-allow-clear {
  margin-left: 15px !important;
}

.input-a {
  margin-left: 15px;
  height: 32px;
  font-size: 12px;
}
/deep/ .ant-input {
  height: 32px;
  font-size: 13px;
}
.pages {
  margin-top: 15px;
}
.tables {
  margin-top: 15px;
}
</style>